package com.maket.scxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.scxx.feign.GetCodeFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.maket.scxx.domain.GylxProcessRoute;
import com.maket.scxx.service.IGylxProcessRouteService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺路线Controller
 * 
 * @author ruoyi
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/gyRoad")
public class GylxProcessRouteController extends BaseController
{
    @Autowired
    private IGylxProcessRouteService gylxProcessRouteService;

    /**
     * 查询工艺路线列表
     */
    @RequiresPermissions("scxx:gyRoad:list")
    @GetMapping("/list")
    public TableDataInfo list(GylxProcessRoute gylxProcessRoute)
    {
        startPage();
        List<GylxProcessRoute> list = gylxProcessRouteService.selectGylxProcessRouteList(gylxProcessRoute);
        return getDataTable(list);
    }

    /**
     * 导出工艺路线列表
     */
    @RequiresPermissions("scxx:gyRoad:export")
    @Log(title = "工艺路线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GylxProcessRoute gylxProcessRoute)
    {
        List<GylxProcessRoute> list = gylxProcessRouteService.selectGylxProcessRouteList(gylxProcessRoute);
        ExcelUtil<GylxProcessRoute> util = new ExcelUtil<GylxProcessRoute>(GylxProcessRoute.class);
        util.exportExcel(response, list, "工艺路线数据");
    }

    /**
     * 获取工艺路线详细信息
     */
    @RequiresPermissions("scxx:gyRoad:query")
    @GetMapping(value = "/{gyroadCode}")
    public AjaxResult getInfo(@PathVariable("gyroadCode") String gyroadCode)
    {
        System.out.println(2);
        return success(gylxProcessRouteService.selectGylxProcessRouteByGyroadCode(gyroadCode));
    }

    /**
     * 新增工艺路线
     */
    @Autowired
    private GetCodeFeign getCodeFeign;
    @RequiresPermissions("scxx:gyRoad:add")
    @Log(title = "工艺路线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GylxProcessRoute gylxProcessRoute)
    {
        String code = getCodeFeign.getUser(23);
        gylxProcessRoute.setGyroadCode(code);
        return toAjax(gylxProcessRouteService.insertGylxProcessRoute(gylxProcessRoute));
    }


    /**
     * 修改工艺路线
     */
    @RequiresPermissions("scxx:gyRoad:edit")
    @Log(title = "工艺路线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GylxProcessRoute gylxProcessRoute)
    {
        return toAjax(gylxProcessRouteService.updateGylxProcessRoute(gylxProcessRoute));
    }

    /**
     * 删除工艺路线
     */
    @RequiresPermissions("scxx:gyRoad:remove")
    @Log(title = "工艺路线", businessType = BusinessType.DELETE)
	@DeleteMapping("/{gyroadCodes}")
    public AjaxResult remove(@PathVariable String[] gyroadCodes)
    {
        return toAjax(gylxProcessRouteService.deleteGylxProcessRouteByGyroadCodes(gyroadCodes));
    }
}
